home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / tracebackCode / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.4 KB  |  54 lines

  1. /*
  2.  *  Newsgroups: comp.sys.sgi
  3.  *  Subject: Re: Wanted: traceback subroutine
  4.  *  Summary: Common man's approach
  5.  *  Date: 18 Jul 91 21:50:03 GMT
  6.  * 
  7.  *  Without any knowledge of the stack, the common person can ask dbx to
  8.  *  do a stack trace from his program.  Here is an simple test case:
  9.  *
  10.  *  It's much more expensive, of course.
  11.  *  compile cc test.c , a.out
  12.  */
  13. #include <stdio.h>
  14. #include <signal.h>
  15. extern char *sys_errlist[];
  16. extern int sys_nerr;
  17. #define DIED -1
  18. int proc3(i,j)
  19. int i,j;
  20. {
  21.   int mypid, errno, termsig;
  22.   static char *dbxstring = "                                              ";
  23.   static char *createfile ="                                              ";
  24.   static char *filename = "/tmp/tttttttttt";
  25.   static char *rmfile = "                          ";
  26.   int irr;
  27.   mypid = getpid();
  28.   sprintf(filename + 7, "%d" , mypid);
  29.   sprintf (dbxstring, "echo \"where\nquit\" | dbx -p %d 1>&2",mypid);
  30.   sprintf (createfile, "echo \"where\nquit\" > %s",filename);
  31.   sprintf (rmfile, "rm -rf %s",filename);
  32.   irr = system (dbxstring);
  33.   if (irr != 0)
  34.       perror ("Unable to call dbx for trace");
  35.   if (system (rmfile) < 0)
  36.       fprintf (stderr, "Error unable to remove temp file: %s\n", filename);
  37.   return (0);
  38. }
  39. proc2(i,j)
  40. int i,j;
  41. {
  42.   int kk;
  43.   kk = proc3(j,i);
  44.   if (kk == 0)
  45.     printf ("successfull return from trace\n");
  46. }
  47. main()
  48. {
  49.   int i,j;
  50.   i = 10;
  51.   j = 12;
  52.   proc2(i,j);
  53. }
  54.